package com.example.ourradio;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;

public class WelcomeActivity extends Activity {
	private String mAccessToken = null;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_welcome);
		
		// CookieSyncManager.createInstance(getApplicationContext());
		
		// Restore preferences
        SharedPreferences settings = getSharedPreferences(Utils.PREFS_NAME, 0);
        mAccessToken = settings.getString(Utils.OAUTH_TOKEN, null);
		
		Thread splashThread = new Thread() {
	        @Override
	        public void run() {
	           try {
	              int waited = 0;
	              while (waited < 1000) {
	                 sleep(100);
	                 waited += 100;
	              }
	           } catch (InterruptedException e) {
	              // do nothing
	           } finally {
	              finish();
	              Intent i = new Intent();
	              if (mAccessToken != null) {
	              	  i.setClassName(
	            	      "com.example.ourradio", 
	            		  "com.example.ourradio.MainActivity"
	            	  );
	              } else {
	            	  i.setClassName(
		            	      "com.example.ourradio", 
		            		  "com.example.ourradio.LoginActivity"
		            	  );		              	  
	              }
	              startActivity(i);
	           }
	        }
	     };
	     splashThread.start();
	}
}
